package com.zoulj.task;

import com.zoulj.util.lock.RedisLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * https://www.cnblogs.com/yanghj010/p/10875151.html
 * corn从左到右（用空格隔开）：秒 分 小时 月份中的日期 月份 星期中的日期 年份
 **/
@Component
public class ScheduledJob {

    public static final Logger log = LoggerFactory.getLogger(ScheduledJob.class);

    @Autowired
    private RedisTemplate redisTemplate;

    //@Scheduled(cron = "0/5 * * * * ?")
    public void autoSendMsg(){
        try(RedisLock redisLock = new RedisLock(redisTemplate, "autoSms", 30)){
            if(redisLock.getLock()){
                log.info(new Date()+":发送短信1999992919");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
